package com.midian.model.user.vo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.midian.common.system.SysStatic;

/**
 * 用户VO
 * @author Mengfh
 *
 */
public class UserInfoVo implements Serializable {
	
	private static final long serialVersionUID = -4916571397662899374L;
	
	/**主键*/
	private String id;
	/**帐号*/
	private String account;
	/**密码*/
	private String password;
	/**姓名*/
	private String name;
	/**是否为超级管理员*/
	private Integer isAdmin;
	/**用户权限集合（key：权限id，value：权限key）*/
	private Map<String, String> authMap = new HashMap<String, String>();
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(Integer isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	public Map<String, String> getAuthMap() {
		return authMap;
	}

	public void setAuthMap(Map<String, String> authMap) {
		this.authMap = authMap;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 检测用户权限
	 * @param auths 需要被验证的权限细项列表
	 * @return
	 */
	public boolean checkFunAuth(String auth) {
		String[] auths = {auth};
		return checkFunAuth(auths);
	}

	/**
	 * 检测用户权限
	 * @param auths 需要被验证的权限细项列表
	 * @return
	 */
	public boolean checkFunAuth(String[] auths) {
		//登录用户是否为Admin
		boolean isAdminCondition = SysStatic.NORMALDELFLAG.equals(this.isAdmin);
		//登录用户是否包含需要被验证的权限（需要被验证的权限细项列表中，只要有一个通过即可）
		boolean authCondition = false;
		if(auths != null && auths.length > 0) {
			for (String auth : auths) {
				if(this.authMap != null && this.authMap.containsValue(auth)) {
					authCondition = true;
					break;
				}
			}
		}
		return isAdminCondition || authCondition;
	}
}
